Have a fallback for an empty response
authorCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Tue, 29 Nov 2016 21:09:00 +0000 (16:09 -0500)
committerCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Sat, 3 Dec 2016 16:12:52 +0000 (11:12 -0500)
This happens in tests.

src/crates-io/lib.rs

index 12c195edbc5a499aea7f3f689088995d9f7a854f..e35d824403380c389dc8d9212df10a6939253798 100644 (file)
@@ -202,7 +202,11 @@ impl Registry {
             body.read(buf).unwrap_or(0)
         })?;
         // Can't derive RustcDecodable because JSON has a key named "crate" :(
-        let response = Json::from_str(&body)?;
+        let response = if body.len() > 0 {
+            Json::from_str(&body)?
+        } else {
+            Json::from_str("{}")?
+        };
         let invalid_categories: Vec<String> =
             response
                 .find_path(&["warnings", "invalid_categories"])